package com.chenzp.rocketmq.filter;

import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;

/**
 * @Classname TagProducer
 * @Description
 * @Version 1.0.0
 * @Date 2025-06-13 16:39
 * @Created by ncs
 */
@Slf4j
public class TagProducer {

    @SneakyThrows
    public static void main(String[] args) {
        DefaultMQProducer defaultMQProducer = new DefaultMQProducer("my-group-producer");
        defaultMQProducer.setNamesrvAddr("192.168.125.102:9876");
        defaultMQProducer.start();
        String[] tags = new String[]{"TagA", "TagB", "TagC"};
        for (int i = 0; i < 15; i++) {
            Message message = new Message("TagTopicTest", tags[i%3],
                    ("tag消息" + i).getBytes(StandardCharsets.UTF_8));
            SendResult sendResult = defaultMQProducer.send(message);
            log.info("tag消息发送结果{}", sendResult);
        }
        defaultMQProducer.shutdown();
    }
}
